/**
 * 前端传值 本地保存；localStroge sessionStrong
 * @type {string|*}
 * JS 中遍历出来的数据需要改很多
 *
 */
var strArray = location.search;
console
//  页面建传值通过URL 获取
// 上个页面传递过来的值
if (strArray.length != 0) {
    orderId = strArray.split("?")[1].split("=")[1];
} else {
    alert('未获取值')
}

//  发送请求获取账单信息
function ta() {
    var newTime = timeAll();
    var timeStamp = "timeStamp:" + newTime + "BM" + "orderId:" + orderId + 'BM';
    var signs = md5(timeStamp);
    signs = signs.toUpperCase();

    $.ajax({
        type: "get",
        url: webUrl + "mywallet/getOrderDetail",
        data: {
            "timeStamp": newTime,
            "orderId": orderId,
            "sign": signs,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            console.log(data)
            var listStr;
            if (data.status == 200) {
                // localStorage.setItem("shopAdress", data.data.location);  //设置键的值
                // $("#shopName").html(data.data.storeName);
                // $("#shopAdress").html(data.data.storeAddress);
                $("#orderNum").html(data.data.orderNum);
                $("#orderCreateDate").html(data.data.createDateStr);
                // var telStr = '<a  href="tel:' + data.data.storetelephone + '">' + '联系商家' +
                //     '</a>';
                // $("#iPhoneId").html(telStr);

                var pingbefor = '<tr>';

                // Type为3是商家未检测
                if (data.data.assessStatus == '3') {

                    //  账单列表  改
                    // $("#iphoneName").html('实际手机型号：' + data.data.productName);
                    // var userPrice = '预估价：' + '<span style="color: red">' + '￥' + data.data.tempProductDetailBo + '</span>';
                    // $("#iphoneprice").html(userPrice);

                    // 机型不一致 3列
                    pingbefor = pingbefor + '<td>机况选项</td>' +
                        '<td>您的选择</td>' +
                        // '<td></td>' +
                        '</tr>';

                    //  订单信息列表 改（机框不一致，机型不一致）
                    var listArr = data.data.tempProductDetailBo;
                    for (var j = 0; j < listArr.attrList.length; j++) {
                        var userproductLIst;
                        if (j % 2 == 0) {
                            userproductLIst = '<tr style="background: white">';
                        } else {
                            userproductLIst = '<tr style="background: #F1F1F1">';
                        }
                        userproductLIst = userproductLIst +
                            '<td>' + listArr.attrList[j].attrCategoryName +
                            '</td>' +
                            '<td>' + listArr.attrList[j].attrName +
                            '</td>' + '</tr>'
                        $("#listDetail").append(userproductLIst);
                    }

                    for (var h = 0; h < listArr.problemList.length; h++) {
                        var probleproductLIst;
                        if (h % 2 == 0) {
                            probleproductLIst = '<tr style="background: white">';
                        } else {
                            probleproductLIst = '<tr style="background: #F1F1F1">';
                        }
                        probleproductLIst = probleproductLIst +
                            '<td>' + listArr.problemList[h].problemCategoryName +
                            '</td>' +
                            '<td>' + listArr.problemList[h].problemName +
                            '</td>' + '</tr>'
                        $("#listDetail").append(probleproductLIst);
                    }

                    // 机况不一致
                } else if (data.data.assessStatus == '1' || data.data.assessStatus == '4') {
                    var listArr = data.data.userProductDetailBo;
                    $("#iphoneName").html('手机型号：' + data.data.productName);
                    $("#iphoneprice").html("估价：" + '￥' + data.data.tempProductDetailBo);
                    var priceFinaly = '最终成交价:' + '<span style="color: #ee0000">' + '￥' + data.data.finalPrice +
                        '</span>'
                    $("#SurePrice").html(priceFinaly);
                    // 表头 4列
                    pingbefor = pingbefor +
                        '<td>机况选项</td>' +
                        '<td>您的选择</td>' +
                        '<td>实际机况</td>' +
                        '<td></td>' +
                        '</tr>';

                    if (data.data.assessStatus == '1') {
                        imgStr = '<div class="yinZimg">' +
                            '<img style="width: 80px" src="../../images/OrderDetail/yinzhang@2x.png">' +
                            '</div>';
                        $("#yinZimg").append(imgStr);
                    } else if (data.data.assessStatus == '1') {
                        $("#yinZimg").append('');
                    }


                    var attrList = data.data.userProductDetailBo.attrList;
                    var problemList = data.data.userProductDetailBo.problemList;
                    // 机况选项
                    var typeArray = '';
                    var userArray = '';
                    var storeAttrList = data.data.storeProductDetailBo.attrList;
                    var storeProblemList = data.data.storeProductDetailBo.problemList;
                    var storeArray = '';

                    for (var j = 0; j < attrList.length; j++) {
                        typeArray = typeArray + attrList[j].attrCategoryName + ',';
                        userArray = userArray + attrList[j].attrName + ',';
                        storeArray = storeArray + storeAttrList[j].attrName + ',';
                    }
                    for (var h = 0; h < problemList.length; h++) {
                        var str = problemList[h].problemCategoryName;
                        str.replace('(', "")
                        var reg = new RegExp("可多选", '');
                        var a = str.replace('(', "");
                        a = a.replace(')', "");
                        a = a.replace(reg, "");
                        typeArray = typeArray + a + ',';
                        userArray = userArray + problemList[h].problemName + ',';
                        storeArray = storeArray + storeProblemList[h].problemName + ',';
                    }

                    typeArray = (typeArray.substring(typeArray.length - 1) == ',') ? typeArray.substring(0, typeArray.length - 1) : typeArray;                    // typeArray = typeArray.split(",");
                    typeArray = typeArray.split(",");
                    userArray = (userArray.substring(userArray.length - 1) == ',') ? userArray.substring(0, userArray.length - 1) : userArray;                    // typeArray = typeArray.split(",");
                    userArray = userArray.split(",");
                    storeArray = (storeArray.substring(storeArray.length - 1) == ',') ? storeArray.substring(0, storeArray.length - 1) : storeArray;                    // typeArray = typeArray.split(",");
                    storeArray = storeArray.split(",");
                    var indexId = data.data.differenceList;

                    for (var i = 0; i < indexId.length; i++) {
                        var probleproductLIst;
                        if (i % 2 == 0) {
                            probleproductLIst = '<tr style="background: white">';
                        } else {
                            probleproductLIst = '<tr style="background: #F1F1F1">';
                        }
                        probleproductLIst = probleproductLIst +
                            '<td>' + typeArray[i] + '</td>' +
                            '<td>' + userArray[i] + '</td>' +
                            '<td>' + storeArray[i] + '</td>';
                        if (indexId[i] == "1") {
                            probleproductLIst = probleproductLIst + '<td>' + '<img style="vertical-align: middle" src="../../images/selected@1x.png">' + '</td>';
                        } else if (indexId[i] == "0") {
                            probleproductLIst = probleproductLIst + '<td>' + '<img style="vertical-align: middle" src="../../images/cuo@1x.png">' + '</td>';
                        } else {
                            probleproductLIst = probleproductLIst + '<td>' + indexId[i] + '</td>';
                        }
                        probleproductLIst = probleproductLIst +
                            '</tr>'
                        $("#listDetail").append(probleproductLIst);
                    }
                    // ************    机型不一致   **********
                } else if (data.data.assessStatus == '2') {
                    $("#iphoneName2").html('检测机型与实际机型不一致');
                    var iphoneName = '实际机型为:' + '<span style=" font-size: 16px;color: #666666">' + data.data.productName +
                        '</span>';
                    $("#SurePrice").html(priceFinaly);
                    $("#iphoneName").html(iphoneName);
                    var priceFinaly = '最终成交价:' + '<span style="color: #ee0000">' + '￥' + data.data.finalPrice + '元' +
                        '</span>';
                    $("#iphoneprice").html(priceFinaly);

                    pingbefor = pingbefor + '<td>机况选项</td>' +
                        '<td>实际机况</td>' + '</tr>';

                    // imgStr = '<div class="yinZimg">' +
                    //     '<img style="width: 100%" src="../../images/OrderDetail/jixing@2x.png">' +
                    //     '</div>';
                    // $("#yinZimg").append(imgStr);

                    var listArr = data.data.storeProductDetailBo;

                    for (var j = 0; j < listArr.attrList.length; j++) {
                        var userproductLIst;
                        if (j % 2 == 0) {
                            userproductLIst = '<tr style="background: white">';
                        } else {
                            userproductLIst = '<tr style="background: #F1F1F1">';
                        }
                        userproductLIst = userproductLIst +
                            '<td>' + listArr.attrList[j].attrCategoryName + '</td>' +
                            '<td>' + listArr.attrList[j].attrName + '</td>' + '</tr>'
                        $("#listDetail").append(userproductLIst);
                    }

                    for (var h = 0; h < listArr.problemList.length; h++) {
                        var probleproductLIst;
                        if (h % 2 == 0) {
                            probleproductLIst = '<tr style="background: white">';
                        } else {
                            probleproductLIst = '<tr style="background: #F1F1F1">';
                        }
                        probleproductLIst = probleproductLIst +
                            '<td>' + listArr.problemList[h].problemCategoryName +
                            '</td>' +
                            '<td>' + listArr.problemList[h].problemName +
                            '</td>' + '</tr>'
                        $("#listDetail").append(probleproductLIst);
                    }
                }
                $("#top").html(pingbefor);
            } else if (data.status == 300) {
                document.location.href = '../login/login.html'
            } else if (data.status == 500) {
                dialog(data.msg);
            }
        },
        error: function (data) {
            //弹出报错内容　　
            dialog("服务器异常")
        }
    })
}


// 返回首页
function backIndex() {
    window.location.href = '../html/index.html';
}